package com.javatimes.test.util;

import java.util.Iterator;
import java.util.Map;

import net.sf.json.JsonConfig;
import net.sf.json.processors.DefaultValueProcessor;
import net.sf.json.processors.JsonValueProcessor;

/**
 * @desc JsonConfig扩展类 ---> 在返回JSON数据前注册值转换处理
 *       继承 jsonConfig 此类事JSON配置类，可以在转换JSON前对JSON数据配置处理
 */
public class JsonConfigEx extends JsonConfig{
	/**
	 * 利用springIOC，容器初始化时依赖注入，将Map中的class类型注册到JSONConfig中
	 * @param processors
	 */
	@SuppressWarnings("unchecked")
	public void setValueProcessors(Map<Class, JsonValueProcessor> processors){
		if(processors != null){
			Iterator<Class> it = processors.keySet().iterator();
			while(it.hasNext()){
				Class clazz = it.next();
				this.registerJsonValueProcessor(clazz, processors.get(clazz));
			}
		}
	}
	
	public void setDefaultProcessors(Map<Class, DefaultValueProcessor> processors){
		if(processors != null){
			Iterator<Class> it = processors.keySet().iterator();
			while(it.hasNext()){
				Class clazz = it.next();
				this.registerDefaultValueProcessor(clazz, processors.get(clazz));
			}
		}
	}

}
